<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .red {
            color: red;
        }
    </style>
</head>

<body>
    <div id="app">
        <input v-model="inputWord" placeholder="请输入单词">
        <h2>你要输入的单词是{{inputWord}}</h2>
        <button @click="add" v.shift="add">添加</button>
        <button @click="deleteWord">删除</button>
        <h3 v-if="judge" :class="{red:judge}">太多了</h3>
        <div>
            <ul :class="{red:judge}">
                单词列表
                <li v-for="(word,index) in words" :key="index">
                    {{word}}
                </li>
            </ul>
        </div>
    </div>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
        const app = Vue.createApp({
            data() {
                return {
                    inputWord: '',
                    words: []
                }
            },
            computed: {
                judge: function () {
                    return this.words.length > 5
                }
            },
            methods: {
                add: function () {
                    if (this.inputWord) {
                        this.words.push(this.inputWord)
                    }
                },
                deleteWord: function () {
                    if (this.words.length > 0) {
                        this.words.pop()
                    }
                },

            }
        })
        app.mount("#app")
    </script>
</body>

</html>